<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>helloVue</title>
</head>

<body>
    <div id='app' title="test">
        <p>{{message}}</p>
    </div>
    <div id="app-2">
        <!-- v-bind:attribute 指令用于绑定数据到元素 -->
        <span v-bind:title='message'>鼠标悬停几秒钟查看此处动态绑定的提示信息！</span>
    </div>
    <div id="app-3">
        <p v-if="seen">现在你看到我了</p>
    </div>
    <div id="app-4">
        <ol>
            <li v-for='todo in todos'>{{todo.text}}</li>
        </ol>
    </div>
    <div id='app-5'>
        <p>{{message}}</p>
        <button v-on:click='reverseMessage'>逆转消息</button>
    </div>
    <div id="app-6">
        <p>{{message}}</p>
        <input type="text" v-model="message">
    </div>

    <script src="js/vue.js"></script>
    <script>
        const app1 = new Vue({
            el: '#app',
            data: {
                message: 'this is a vuejs demo'
            },
            // data() {     // 效果同data:{message:'this is a vuejs demo'}
            //     return {
            //         message: 'this is a vuejs demo!'
            //     }
            // }
        })

        var app2 = new Vue({
            el: '#app-2',
            data: {
                message: '页面加载于' + new Date().toLocaleString()
            }
        })

        var app3 = new Vue({
            el: '#app-3',
            data: {
                seen: false
            }
        })

        var app4 = new Vue({
            el: '#app-4',
            data: {
                todos: [{
                        text: 3.14
                    },
                    {
                        text: 'VueTest'
                    },
                    {
                        text: true
                    }
                ]
            }
        })

        var app5 = new Vue({
            el: '#app-5',
            data: {
                message: '上上下下'
            },
            methods: {
                reverseMessage: function () {
                    this.message = this.message.split('').reverse().join('')
                }
            }
        })

        var app6 = new Vue({
            el: '#app-6',
            data: {
                message: '请输入'
            }
        })

        // 定时器
        self.setTimeout(`app1.message='app1.message'`, 800)
        self.setTimeout(`app3.seen='true'`, 1200)
        setTimeout(`app4.todos.push({ text: '新项目' })`, 1800)
        // setTimeout(`reverseMessage()`,1800)


        var intClock = self.setInterval('show()', 1000)
        let i = 0;

        function show() {
            i++;
            if (i > 1)
                window.clearInterval(intClock)
            console.log(app2.message) //会执行2次
        }
    </script>
</body>

</html>